#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
struct node{
    int i,j,k,t;
    node(int _i,int _j,int _k,int _t):i(_i),j(_j),k(_k),t(_t){}
};
const int N=12;
char mp[2][N][N];
int n,m,t;
int pi,pj,pk;
bool vis[2][N][N];
int dir[4][2]={{-1,0},{0,-1},{1,0},{0,1}};
bool check(int i,int j,int k){
    if(i<0 || i>=n || j<0 || j>=m || k<0 || k>=2){
        return false;
    }
    return true;
}
bool bfs(){
    memset(vis,false,sizeof(vis));
    queue<node> q;
    q.push(node(0,0,0,0));
    vis[0][0][0]=true;
    node now(0,0,0,0);
    while(!q.empty()){
        node tmp=q.front();
        q.pop();
        int ti=tmp.i;
        int tj=tmp.j;
        int tk=tmp.k;
        int tt=tmp.t;
        if(tt>t){
            return false;
        }
        if(ti==pi && tj==pj && tk==pk){
            //printf("%d %d %d %d\n",ti,tj,tk,tt);
            return tt<=t;
        }
        for(int i=0;i<4;i++){
            now.i=ti+dir[i][0];
            now.j=tj+dir[i][1];
            now.k=tk;
            if(!vis[tk][now.i][now.j] && check(now.i,now.j,now.k) && mp[tk][now.i][now.j]!='*'){
                now.t=tt+1;
                //printf("%d %d %d\n",ti+a,tj+b,tk);
                if(mp[tk][now.i][now.j]=='#'){
                    now.k=1-now.k;
                    if(vis[now.k][now.i][now.j] || mp[now.k][now.i][now.j]=='*' || mp[now.k][now.i][now.j]=='#'){
                        continue;
                    }
                }
                q.push(now);
                vis[now.k][now.i][now.j]=true;
            }
        }
    }
    return false;
}
int main(void){
    //freopen("data.txt","r",stdin);
    int c;
    scanf("%d",&c);
    while(c--){
        scanf("%d%d%d",&n,&m,&t);
        for(int i=0;i<n;i++){
            scanf("%s",mp[0][i]);
            for(int j=0;j<m;j++){
                if(mp[0][i][j]=='P'){
                    pi=i;
                    pj=j;
                    pk=0;
                }
            }
        }
        for(int i=0;i<n;i++){
            scanf("%s",mp[1][i]);
            for(int j=0;j<m;j++){
                if(mp[1][i][j]=='P'){
                    pi=i;
                    pj=j;
                    pk=1;
                }
            }
        }
        if(bfs()){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}